<?php if (!defined('BASEPATH')) exit('No direct access allowed.');
/*****
  * This class provides a set of base Controller classes to be utilized with ErkanaAuth
  * @author     Michael Wales
  * @email      webmaster@michaelwales.com
  * @filename   MY_Controller.php
  * @title      ErkanaAuth Controller Library
  * @url        http://www.michaelwales.com/
  * @version    1.0
  *****/

// Controllers accessible by everyone, regardless of login status
class Public_Controller extends Controller {
    function Public_Controller() {
        parent::Controller();
        // Get the user data, in case they are logged in
        $this->data->user = $this->auth->get_user($this->session->userdata('user_id'));
    }
    
    // This function is used to prevent a user from accessing a method if they are logged in
    function no_user_access() {
        if ($this->data->user !== FALSE) {
            redirect('');
        }
    }
}

// Controllers only accessible by logged in users
class Auth_Controller extends Public_Controller {
    function Auth_Controller() {
        if ($this->data->user === FALSE) {
            // The user is not logged in, send them to the homepage
            redirect('');
        }
    }
}

// Controllers only accessible to logged in users that are admins
class Admin_Controller extends Public_Controller {
    function Admin_Controller() {
        parent::Controller();
        if (($this->data->user === FALSE) || ($this->data->user->role != 'admin')) {
            redirect('');
        }
    }
}